from PySide6.QtCore import QObject, Signal, Slot, Property
from PySide6.QtQml import QmlElement, qmlRegisterType

from ViewModel.Home import HomeViewModel


#@QmlElement
class CounterViewModel(QObject):
    countChanged = Signal(int)
    itemsChanged = Signal(list)
    def __init__(self, parent=None):
        super().__init__(parent)
        self._count = 0
        self._items = ["Item 1", "Item 2", "Item 3"]
        self.home = HomeViewModel()
   
    @Property(int, notify=countChanged)
    def count(self):
        return self._count
    
    @Property(list, notify=itemsChanged)
    def items(self):
        return self._items
    @Slot()
    def increment(self):
        self._count +=1
        self.countChanged.emit(self._count)
    @Slot()
    def decrement(self):
        self._count-=1
        self.countChanged.emit(self._count)
    @Slot()
    def addItem(self):
        self._items.append("Item "+str(len(self.items)+1))
        self.itemsChanged.emit(self._items)
# 将类暴露给 QML
#qmlRegisterType(CounterViewModel, 'CounterViewModel', 1, 0,)